import React from 'react'

import avatar from '../../assets/images/avatar.png'

class CommentSend extends React.PureComponent {
  state = {
    comment: ''
  }

  onCommentChange = e => {
    this.setState({
      comment: e.target.value
    })
  }

  onSendComment = () => {
    const { comment } = this.state

    if (!comment) return

    this.props.onSend(this.state.comment)

    this.setState({ comment: '' })
  }

  render() {
    return (
      <div className="comment-send">
        <div className="user-face">
          <img className="user-head" src={avatar} alt="" />
        </div>
        <div className="textarea-container">
          <textarea
            cols="80"
            rows="5"
            placeholder="发条友善的评论"
            className="ipt-txt"
            value={this.state.comment}
            onChange={this.onCommentChange}
          />
          <button className="comment-submit" onClick={this.onSendComment}>
            发表评论
          </button>
        </div>
        <div className="comment-emoji">
          <i className="face"></i>
          <span className="text">表情</span>
        </div>
      </div>
    )
  }
}

export default CommentSend
